package com.itheima.wemedia.controller;

import com.itheima.common.vo.ResultVo;
import com.itheima.wemedia.pojo.WmUser;
import com.itheima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version 1.0
 * @description 说明
 * @package com.itheima.wemedia.controller
 */
@RestController
public class ApiController {

    @Autowired
    private WmUserService wmUserService;

    //通过ap_user_id查询 wm_user表
    // apUserId=null /api/wmUser/getByApUserId/  404
    @GetMapping("/api/wmUser/getByApUserId/{apUserId}")
    public ResultVo<WmUser> getByApUserId(@PathVariable(value = "apUserId") Long apUserId){
        WmUser wmUser = wmUserService.findByApUserId(apUserId);
        return ResultVo.ok(wmUser);
    }

    //创建WmUser对象
    @PostMapping("/api/wmUser/add")
    public ResultVo<WmUser> addWmUser(@RequestBody WmUser wmUser){
        wmUserService.save(wmUser);
        // wmUser有没有id?
        return ResultVo.ok(wmUser);
    }
}
